import json

from flask import jsonify
from qiniu import Auth, put_data

access_key = "M2i7e9iK-90DHJnR10anb7Na0wBddTkpf_lmDjLD"
secret_key = "ddLE0dhu3YvYBvpK3PriqiqVaVqYHX1_djRdLgRe"
bucket_name = "my_storage1"


def storage(data):
    try:
        q = Auth(access_key, secret_key)
        token = q.upload_token(bucket_name)
        ret, info = put_data(token, None, data)
        #print(ret, info)
        return info
    except Exception as e:
        raise e;

    if info.status_code != 200:
        raise Exception("上传图片失败")
    return ret["key"]

#F:\QQ浏览器下载\image1.jpg
if __name__ == '__main__':
    file = input('请输入文件路径')
    with open(file, 'rb') as f:
        info=storage(f.read())
    #print(info.text_body)
    #print(json.loads(info.text_body)['key'])